package hasthi.manager.gui;

import static hasthi.manager.gui.GUIConstants.RESOURCE_RADIOUS;
import hasthi.common.HasthiException;
import hasthi.common.constants.WSDMConstants.SystemState;
import hasthi.metamodel.resource.ManagedResource;

import java.awt.Color;
import java.awt.Graphics;

import javax.xml.namespace.QName;

public class ResourceCanvas {
    private final ManagedResource resource;

    public ResourceCanvas(final ManagedResource resource) {
        this.resource = resource;
    }

    public void paint(Graphics g,int x,int y) {
        try {
            Color c = Color.GREEN;
            SystemState state = SystemState.valueOf(resource.getState());
            switch(state){
                case BusyState: case SaturatedState:
                    c = Color.ORANGE;
                    break;
                case CrashedState:
                    c = Color.RED;
                    break;
                case IdleState:
                    c = Color.GREEN;
                    break;
                case StoppedState:
                    c = Color.CYAN;
                    break;
                        
            }
            g.setColor(c);
            g.fillOval(RESOURCE_RADIOUS +x,RESOURCE_RADIOUS +y,RESOURCE_RADIOUS*2,RESOURCE_RADIOUS*2);
        } catch (HasthiException e) {
            e.printStackTrace();
        }
    }
    
    public QName getName(){
        return resource.getQName();
    }
}
